{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5e35a070",
   "metadata": {},
   "source": [
    "------\n",
    "* 学习人：纪秋霞\n",
    "* 时间：2021-11-25\n",
    "* week13\n",
    "* 学习线上资源：\n",
    "\n",
    "> 1.[python官方文档](https://python.org/doc)\n",
    "\n",
    "> 2.[老师博客](https://www.cnblogs.com/xuzhichao)\n",
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "addceaa5",
   "metadata": {},
   "source": [
    "# 1. 上周回顾\n",
    "\n",
    "## 1.1 Json(文本数据) ---> Dict(python中的字典数据)\n",
    "\n",
    "## 1.2 字典喝列表的综合实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9134899e",
   "metadata": {},
   "source": [
    "# 2. 本周内容\n",
    "\n",
    "## 2.1 [集合](https://docs.python.org/3/tutorial/datastructures.html#sets)\n",
    "\n",
    "> 1. 集合的性质\n",
    ">> 1. 无序（unordered）\n",
    ">> 2. 不重复的（no_duplicate）\n",
    "> 2. 集合的一般方法\n",
    ">> 1. 增加\n",
    ">> 2. 删除\n",
    ">> 3. 查询： 用 in 查询\n",
    "> 3. 集合的数学逻辑运算"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "618da9e2",
   "metadata": {},
   "source": [
    "### 1. 集合的性质及概念\n",
    "* 思考：我想了解一组数据中有哪些唯一存在的值？（假如是列表）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "21ca18a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考题\n",
    "no_duplicate_age = []\n",
    "list_age = [18,24,25,24,18,23,18]\n",
    "for i in list_age:\n",
    "    if i not in no_duplicate_age:\n",
    "        no_duplicate_age.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "904bb4f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 24, 25, 23]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "no_duplicate_age"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d233482e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{24, 25, 18, 23}\n"
     ]
    }
   ],
   "source": [
    "# list---> set 的方法：set()\n",
    "no_duplicate_age_set = set(list_age)\n",
    "print(no_duplicate_age_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0b2a6747",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'banana', 'apple', 'pear', 'orange'}\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 官网测试代码\n",
    "\n",
    "# 1. 移除重复项\n",
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(basket)\n",
    "# show that duplicates have been removed\n",
    "\n",
    "# 2. in 查询成员关系（是否存在）\n",
    "print('orange' in basket )\n",
    "print('crabgrass' in basket)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00a125d9",
   "metadata": {},
   "source": [
    "### 2. 集合的一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b300098c",
   "metadata": {},
   "source": [
    "* 集合的创建的两种一般方法\n",
    "> 1. set(list)\n",
    "> 2. 直接按照集合的结构创建： {value1,value2,value3,...}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32a121ee",
   "metadata": {},
   "source": [
    "> 1. 增加\n",
    ">> 1. 结果： add() : Add an element to a set.\n",
    ">> 2. 注意：This has no effect if the element is already present."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f4536099",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 66, 3, 4, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "set_1 = set([1,3,4,0,8,66,7])\n",
    "print(set_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "64d4cd66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function add:\n",
      "\n",
      "add(...) method of builtins.set instance\n",
      "    Add an element to a set.\n",
      "    \n",
      "    This has no effect if the element is already present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 不用append 是因为 append 是添加到某一数据末尾，而集合是无序的，所以不用append\n",
    "\n",
    "help(set_1.add)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7faa0ba5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 66, 3, 4, 99, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "set_1.add(99)\n",
    "print(set_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1bc12c9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 66, 3, 4, 99, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "set_1.add(66)\n",
    "print(set_1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61df533a",
   "metadata": {},
   "source": [
    "> 2. 删除\n",
    ">> 1. pop()\n",
    ">> 2. remove()\n",
    ">> 3. discard()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "55ff0c34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 66, 3, 4, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "set_1 = set([1,3,4,0,8,66,7])\n",
    "print(set_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ec679e82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(...) method of builtins.set instance\n",
      "    Remove and return an arbitrary set element.\n",
      "    Raises KeyError if the set is empty.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# pop()随机删除一个数\n",
    "help(set_1.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "9d4539cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 66, 3, 4, 7, 8}\n",
      "{1, 66, 3, 4, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "# 1. Remove and return an arbitrary set element.\n",
    "print(set_1)\n",
    "set_1.pop()\n",
    "print(set_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "650e4f98",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'pop from an empty set'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-20-0defeaec728f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 2. Raises KeyError if the set is empty.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mset_2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mset_2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: 'pop from an empty set'"
     ]
    }
   ],
   "source": [
    "# 2. Raises KeyError if the set is empty.\n",
    "set_2 = set([])\n",
    "set_2.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "11325510",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(...) method of builtins.set instance\n",
      "    Remove an element from a set; it must be a member.\n",
      "    \n",
      "    If the element is not a member, raise a KeyError.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(set_1.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5ff348d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 66, 3, 4, 7, 8}\n",
      "{1, 3, 4, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "# 1. Remove an element from a set; it must be a member.\n",
    "print(set_1)\n",
    "set_1.remove(66)\n",
    "print(set_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6ba768cb",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "66",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-24-65d050c2e95e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mset_1\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m66\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: 66"
     ]
    }
   ],
   "source": [
    "# 2. If the element is not a member, raise a KeyError.\n",
    "# 一般项目中 remove（）会和 in 共同使用\n",
    "set_1.remove(66)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "bf5515dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 避免key error\n",
    "if 66 in set_1:\n",
    "    set_1.remove(66)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "e22af831",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function discard:\n",
      "\n",
      "discard(...) method of builtins.set instance\n",
      "    Remove an element from a set if it is a member.\n",
      "    \n",
      "    If the element is not a member, do nothing.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(set_1.discard)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "5aeb2935",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 3, 4, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "print(set_1)\n",
    "set_1.discard(66)\n",
    "# 无法判断元素是否存在\n",
    "# 但是不会报错"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7e4fd1d",
   "metadata": {},
   "source": [
    "### 3. 集合的数学逻辑运算\n",
    "\n",
    "> 1. 集合的交集\n",
    "> 2.集合的并集\n",
    "> 3.集合的差集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "5202d096",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "set_1 = set([1,2,5,6,7,2,3,2,4,4])\n",
    "set_2 = set([1,3,4,0,8,66,7])\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffe4f7db",
   "metadata": {},
   "source": [
    "> 1. 集合的交集\n",
    ">> 1. 使用集合的方法： set_1.intersection(set_2)\n",
    ">> 2. 使用逻辑运算符：set_1 & set_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "04184ad0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function intersection:\n",
      "\n",
      "intersection(...) method of builtins.set instance\n",
      "    Return the intersection of two sets as a new set.\n",
      "    \n",
      "    (i.e. all elements that are in both sets.)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(set_1.intersection)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "bdb3c6ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "交集结果 ： {1, 3, 4, 7}\n"
     ]
    }
   ],
   "source": [
    "# A. 使用交集的方法： set_1.intersection(set_2)\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"交集结果 ：\",set_1.intersection(set_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "970ae9d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "交集结果 ： {1, 3, 4, 7}\n"
     ]
    }
   ],
   "source": [
    "# B. 使用逻辑运算符：set_1 & set_2\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"交集结果 ：\",set_1 & set_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69cd163c",
   "metadata": {},
   "source": [
    "> 2. 集合的并集\n",
    ">> 1. 使用并集的方法：set_1.union(set_2)\n",
    ">> 2. 使用逻辑运算符：set_1 | set_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ad42a92c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "并集结果 ： {0, 1, 2, 3, 4, 5, 6, 7, 66, 8}\n"
     ]
    }
   ],
   "source": [
    "# A. 使用并集的方法： set_1.union(set_2)\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"并集结果 ：\",set_1.union(set_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "302c2d34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "并集结果 ： {0, 1, 2, 3, 4, 5, 6, 7, 66, 8}\n"
     ]
    }
   ],
   "source": [
    "# B. 使用逻辑运算符：set_1 & set_2\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"并集结果 ：\",set_1 | set_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "fa509c99",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始的时间： 1637811012.2350218\n",
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "并集结果 ： {0, 1, 2, 3, 4, 5, 6, 7, 66, 8}\n",
      "结束的时间： 1637811012.2360141\n",
      "运行的时间： 0.0009922981262207031\n"
     ]
    }
   ],
   "source": [
    "# 计算运行效率 = （运行后的时间结点 - 运行前的时间结点）\n",
    "# 思考并对比 列表运算的执行效率 （算法的优化常考虑运行效率）\n",
    "import time\n",
    "start_time = time.time()\n",
    "print(\"开始的时间：\",start_time)\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"并集结果 ：\",set_1 | set_2)\n",
    "stop_time = time.time()\n",
    "print(\"结束的时间：\",stop_time)\n",
    "print(\"运行的时间：\",stop_time - start_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88e3ad02",
   "metadata": {},
   "source": [
    "> 3. 集合的差集(考虑先后顺序)\n",
    ">> 1. 使用差集的方法：set_1.difference(set_2)\n",
    ">> 2. 使用逻辑运算符：set_1 - set_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e8750a20",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "set_1 - stt_2 的差集结果 ： {2, 5, 6}\n"
     ]
    }
   ],
   "source": [
    "# A.1 使用并集的方法： set_1.difference(set_2)\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"set_1 - set_2 的差集结果 ：\",set_1.difference(set_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "5151ba7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "set_2 - set_1 的差集结果 ： {0, 8, 66}\n"
     ]
    }
   ],
   "source": [
    "# A.2 使用并集的方法： set_2.difference(set_1)\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"set_2 - set_1 的差集结果 ：\",set_2.difference(set_1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c78d5d3d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "差集结果 ： {2, 5, 6}\n"
     ]
    }
   ],
   "source": [
    "# B. 使用逻辑运算符：set_1 - set_2\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"差集结果 ：\",set_1 - set_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00259423",
   "metadata": {},
   "source": [
    "> 4. 对称差集 （集合A与集合B中所有不属于A∩B的元素的集合）或 (两个差集合并)\n",
    ">> 1. 使用对称差集的方法：set_1.symmetric_difference(set_2)\n",
    ">> 2. 使用逻辑运算符：？---> (set_1 - set_2)|(set_2 - set_1)\n",
    "* 交集结果 ： {1, 3, 4, 7}\n",
    "* (set_1 - set_2)|(set_2 - set_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "bb69c2fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "对称差集结果 ： {0, 66, 2, 5, 6, 8}\n"
     ]
    }
   ],
   "source": [
    "# A. 使用对称差集的方法：set_1.symmetric_difference(set_2)\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"对称差集结果 ：\",set_1.symmetric_difference(set_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "db9977d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set_1: {1, 2, 3, 4, 5, 6, 7}\n",
      "set_2: {0, 1, 66, 3, 4, 7, 8}\n",
      "差集结果 ： {0, 2, 66, 5, 6, 8}\n"
     ]
    }
   ],
   "source": [
    "# B. 使用逻辑运算符：？\n",
    "print(\"set_1:\",set_1)\n",
    "print(\"set_2:\",set_2)\n",
    "print(\"差集结果 ：\",(set_1 - set_2)|(set_2 - set_1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d0f2f5c",
   "metadata": {},
   "source": [
    "### 集合实践：P129\n",
    "\n",
    "---------\n",
    "\n",
    "vowels = set('aeiou')\n",
    "\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "\n",
    "found = vowels.intersection(set(word))\n",
    "\n",
    "for vowel in found:\n",
    "\n",
    "    print(vowel)\n",
    "    \n",
    "-----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c8af833",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = set('aeiou')\n",
    "print(\"vowels:\",vowels)\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "print(\"word:\",set(word))\n",
    "found = vowels.intersection(set(word))\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "954ce75f",
   "metadata": {},
   "source": [
    "## 课后作业\n",
    "\n",
    "1.课堂练习\n",
    "\n",
    "2.课本第三章 课后项目练习\n",
    "\n",
    "3.总结集合方法"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
